package com.game.eggscatcher.GameHelpers;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion;
import com.badlogic.gdx.graphics.g2d.TextureRegion;

public class AssetLoader {
	private static final String KEY = "highScore";
	public static BitmapFont text, handyText;
	private static TextureAtlas textureAtlas;
	public static AtlasRegion egg, ga, vit, ngan, ro, shit;
	public static Sound scored, dropped, laid, shit_catched, level_up, game_over;
	public static Preferences prefs;
	public static void load(){
		prefs = Gdx.app.getPreferences("EggsCatcher");
		if (!prefs.contains(KEY)) {
			prefs.putInteger(KEY, 0);
		}
		handyText = new BitmapFont(Gdx.files.internal("data/handy.fnt"));
		
		text = new BitmapFont(Gdx.files.internal("data/bubble.fnt"));
		text.setScale(.10f, -.10f);
		text.setColor(Color.GREEN);
		textureAtlas = new TextureAtlas(Gdx.files.internal("data/eggs.atlas"));
		egg = textureAtlas.findRegion("egg");
		egg.flip(false, true);
		ga = textureAtlas.findRegion("ga");
		ga.flip(false, true);
		vit = textureAtlas.findRegion("vit");
		vit.flip(false, true);
		ngan = textureAtlas.findRegion("ngan");
		ngan.flip(false, true);
		ro = textureAtlas.findRegion("Ro");
		ro.flip(false, true);
		shit = textureAtlas.findRegion("shit");
		shit.flip(false, true);
		
		scored = Gdx.audio.newSound(Gdx.files.internal("data/scored.wav"));
		dropped = Gdx.audio.newSound(Gdx.files.internal("data/dropped.wav"));
		laid = Gdx.audio.newSound(Gdx.files.internal("data/laid.wav"));
		shit_catched = Gdx.audio.newSound(Gdx.files.internal("data/shit_catched.wav"));
		level_up = Gdx.audio.newSound(Gdx.files.internal("data/level_up.wav"));
		game_over = Gdx.audio.newSound(Gdx.files.internal("data/game_over.mp3"));
	} 
	public static void resetHighScore() {
		prefs.putInteger(KEY, 0);
		prefs.flush();
	}
	public static void setHighScore(int score){
		prefs.putInteger(KEY, score);
		prefs.flush();
	}
	public static int getHighScore() {
		return prefs.getInteger(KEY);
	}
	public static void dispose() {
		textureAtlas.dispose();
		text.dispose();
		//dispose sounds
		scored.dispose();
		dropped.dispose();
		laid.dispose();
		shit_catched.dispose();
		level_up.dispose();
		game_over.dispose();
	}
}
